Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an incorrect number of zero bytes being inserted between sections #44

Merged
merged 3 commits into from
Oct 29, 2021

Conversation

yvt
Copy link
Contributor

@yvt yvt commented Oct 26, 2021

This PR fixes a bug in the elf_to_bin function.

When processing the i-th section (where i > 0), start[i] - (start[0] + len[i - 1]) zero bytes are inserted after that section. This doesn't make any sense and causes sections to be written at incorrect locations under certain circumstances.

This PR updates the code so that start[i] - (start[i - 1] + len[i - 1]) = start[i] - end[i - 1] zero bytes are inserted before each section.

@jacobrosenthal
Copy link
Owner

Man that loop has all the bugs. Do you have a binary showing the problem we can add to those test cases?

@jacobrosenthal
Copy link
Owner

And does this by any chance close #38
can we get @sinyo-matu to confirm if so?

@yvt
Copy link
Contributor Author

yvt commented Oct 27, 2021

Do you have a binary showing the problem we can add to those test cases?

The problem is exhibited by an example from my RTOS, but I think I can whip up a smaller test case.

And does this by any chance close #38 can we get @sinyo-matu to confirm if so?

No, it's unrelated.

@yvt yvt changed the title Fix extra zero bytes being inserted between sections Fix an incorrect number of zero bytes being inserted between sections Oct 28, 2021
@yvt yvt force-pushed the fix-elftobin branch 2 times, most recently from 2abaa79 to b05388a Compare October 28, 2021 12:37
yvt added 2 commits October 28, 2021 21:38
When processing the `i`-th section (where `i > 0`), `start[i] -
(start[0] + len[i - 1])` zero bytes are inserted *after* that section.
This doesn't make sense and causes sections to be written at incorrect
locations under certain circumstances.

This commit updates the code in order that `start[i] - (start[i - 1] +
len[i - 1])` = `start[i] - end[i - 1]` zero bytes are inserted *before*
each section.
@jacobrosenthal
Copy link
Owner

jacobrosenthal commented Oct 29, 2021

I threw a commit on unifying the if statements that I think is an improvement.

Is this done? It tested a pygamer and it still works with this patch so seems ok

@yvt
Copy link
Contributor Author

yvt commented Oct 29, 2021

Yep, it's ready to merge.

@jacobrosenthal jacobrosenthal merged commit 638417a into jacobrosenthal:master Oct 29, 2021
@Rahix
Copy link

Rahix commented Nov 23, 2021

Just as a datapoint: The linker script changes in cortex-m-rt 0.7 seem to reliably trigger this bug. Glad it's fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants